package cn.shop.dys.activity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import cn.shop.lib_common.CommonUtil;
import cn.shop.dys.R;

/**
 *
 * 基类
 * Created by sunjian on 2016/4/18.
 *
 */
public abstract class MyBaseActivity extends AppCompatActivity {
    @ViewInject(R.id.iv_common_back)
    protected ImageView mCommonBack;
    @ViewInject(R.id.tv_common_index_titile)
    protected TextView mCommonIndexTitle;
    @ViewInject(R.id.iv_common_settings)
    protected ImageView mCommonSettings;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getChildLayoutResID());
        ViewUtils.inject(this);
        mCommonSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initPopupWindow(v);
            }
        });
    }
    private void initPopupWindow (View view){
        View pwView = View.inflate(this, R.layout.view_popupwindow, null);
        PopupWindow popupWindow = new PopupWindow(pwView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setBackgroundDrawable(new ColorDrawable());
        popupWindow.setAnimationStyle(R.style.PopupWindowAnimation);
        int[] location = new int[2];
        view.getLocationInWindow(location);
        popupWindow.showAsDropDown(view, (int) -CommonUtil.dpToPx(this, 100), (int) -CommonUtil.dpToPx(this, 0));
        //  popupWindow.showAtLocation(view, Gravity.RIGHT| Gravity.TOP, location[0]+40, location[1] + 40);
    }

    public abstract int getChildLayoutResID();
}
